package com.friddle.login.taobao.UA;

import java.io.FileReader;
import java.io.Reader;

import javax.script.ScriptEngine;

import com.sun.script.javascript.RhinoScriptEngine;

/**
 * Created by friddle on 15-1-31.
 */
public class UaJsAnalysis {
	ScriptEngine mEngine = new RhinoScriptEngine();

	public void initEnvironment(String log) throws Exception {
		Reader readerenv = new FileReader("src/main/resources/taobao/envinit.js");
		Reader reader = new FileReader("src/main/resources/taobao/taobaoinit.js");
		mEngine.eval("var log=" + log);
		mEngine.eval(readerenv);
		mEngine.eval(reader);
	}

	public void parseJs() throws Exception {
		Reader readerua = new FileReader("src/main/resources/taobao/ua.js");
		mEngine.eval(readerua);
		String ua = mEngine.eval("UA_Opt").toString();
		System.out.println(ua);
	}

	public static void main(String[] args) throws Exception {
		UaJsAnalysis mAnlalysis = new UaJsAnalysis();
		mAnlalysis.initEnvironment("1212121212112");
		mAnlalysis.parseJs();
	}

}
